<?php

namespace app\api\controller\shop;


use app\admin\model\Shopbalanceprofit;
use app\admin\model\Shopcharge;
use app\admin\model\Shopdaytrade;
use app\admin\model\Shoporder;
use app\admin\model\Shoporderprofit;
use app\admin\model\Shoproom;
use app\admin\model\Shopstaff;
use app\admin\model\Shoptableorder;
use app\admin\model\Tuanorder;
use app\admin\model\Useragent;
use app\admin\model\Userbalance;
use app\admin\model\Usercard;
use app\admin\model\Userwithdraw;
use app\api\service\BalanceService;
use app\api\service\BankService;
use app\api\service\CommonService;
use app\common\controller\Api;

/**
 *
 */
class Data extends Api
{
    protected $noNeedLogin = [];
    protected $noNeedRight = ['*'];


    public function index()
    {

        $shop_id = $this->request->param('shop_id');
        $date = $this->request->param('date');
        $start = $this->request->param('start');
        $startDate = $this->request->param('startDate');
        $endDate = $this->request->param('endDate');

        $shopOrderModel = new Shoporder();
        $where = array();
        $where['shop_id'] = $shop_id;
        $where['status'] = array('not in', ['paying', 'refund']);
        $shopOrderProfitModel = new Shoporderprofit();
        $chargeModel = new Shopcharge();

        $ret = array();
        $userList = $shopOrderModel->where('shop_id', $shop_id)->group('user_id')->select();
        $ret['totalUser'] = count($userList);

        error_log("=date===" . $date);
        if ($date == '今天') {
            $chargeAmount = $chargeModel->whereTime('create_time', 'today')->where($where)->sum('amount');
            $totalAmount = $shopOrderModel->whereTime("create_time", 'today')->where($where)->sum('amount');
            $totalOrder = $shopOrderModel->whereTime("create_time", 'today')->where($where)->count('id');
            $profit = $shopOrderProfitModel->whereTime('create_time', 'today')->where('shop_id', $shop_id)->sum('amount');

            $totalBalance = $shopOrderModel->whereTime('create_time', 'today')->where($where)->sum('balance');

            error_log("======" . $profit);
            $ret['totalAmount'] = $totalAmount;
            $ret['totalOrder'] = $totalOrder;
            $ret['profit'] = $profit;
            $ret['chargeAmount'] = $chargeAmount;
            $ret['totalBalance'] = $totalBalance;


            $refundAmount = $shopOrderModel->whereTime('create_time', 'today')->where('status', 'refund')->where('shop_id', $shop_id)->sum('amount');
            $ret['refundAmount'] = $refundAmount;

            $us = $shopOrderModel->whereTime("create_time", 'today')->where($where)->group('user_id')->select();
            $ret['users'] = count($us);


        } else if ($date == '昨天') {

            $chargeAmount = $chargeModel->whereTime('create_time', 'yesterday')->where($where)->sum('amount');
            $totalAmount = $shopOrderModel->whereTime("create_time", 'yesterday')->where($where)->sum('amount');
            $totalOrder = $shopOrderModel->whereTime("create_time", 'yesterday')->where($where)->count('id');
            $profit = $shopOrderProfitModel->whereTime('create_time', 'yesterday')->where('shop_id', $shop_id)->sum('amount');

            $totalBalance = $shopOrderModel->whereTime('create_time', 'yesterday')->where($where)->sum('balance');

            $ret['totalAmount'] = $totalAmount;
            $ret['totalOrder'] = $totalOrder;
            $ret['profit'] = $profit;
            $ret['chargeAmount'] = $chargeAmount;
            $ret['totalBalance'] = $totalBalance;


            $refundAmount = $shopOrderModel->whereTime('create_time', 'yesterday')->where('status', 'refund')->where('shop_id', $shop_id)->sum('amount');
            $ret['refundAmount'] = $refundAmount;

            $us = $shopOrderModel->whereTime("create_time", 'yesterday')->where($where)->group('user_id')->select();
            $ret['users'] = count($us);

        } else if ($date == '本周') {

            $chargeAmount = $chargeModel->whereTime('create_time', 'week')->where($where)->sum('amount');
            $totalAmount = $shopOrderModel->whereTime("create_time", 'week')->where($where)->sum('amount');
            $totalOrder = $shopOrderModel->whereTime("create_time", 'week')->where($where)->count('id');
            $profit = $shopOrderProfitModel->whereTime('create_time', 'week')->where('shop_id', $shop_id)->sum('amount');

            $totalBalance = $shopOrderModel->whereTime('create_time', 'week')->where($where)->sum('balance');

            $ret['totalAmount'] = $totalAmount;
            $ret['totalOrder'] = $totalOrder;
            $ret['profit'] = $profit;
            $ret['chargeAmount'] = $chargeAmount;
            $ret['totalBalance'] = $totalBalance;


            $refundAmount = $shopOrderModel->whereTime('create_time', 'week')->where('status', 'refund')->where('shop_id', $shop_id)->sum('amount');
            $ret['refundAmount'] = $refundAmount;

            $us = $shopOrderModel->whereTime("create_time", 'week')->where($where)->group('user_id')->select();
            $ret['users'] = count($us);

        } else if ($date == '上周') {

            $chargeAmount = $chargeModel->whereTime('create_time', 'last week')->where($where)->sum('amount');
            $totalAmount = $shopOrderModel->whereTime("create_time", 'last week')->where($where)->sum('amount');
            $totalOrder = $shopOrderModel->whereTime("create_time", 'last week')->where($where)->count('id');
            $profit = $shopOrderProfitModel->whereTime('create_time', 'last week')->where('shop_id', $shop_id)->sum('amount');

            $totalBalance = $shopOrderModel->whereTime('create_time', 'last week')->where($where)->sum('balance');

            $ret['totalAmount'] = $totalAmount;
            $ret['totalOrder'] = $totalOrder;
            $ret['profit'] = $profit;
            $ret['chargeAmount'] = $chargeAmount;
            $ret['totalBalance'] = $totalBalance;

            $refundAmount = $shopOrderModel->whereTime('create_time', 'last week')->where('status', 'refund')->where('shop_id', $shop_id)->sum('amount');
            $ret['refundAmount'] = $refundAmount;

            $us = $shopOrderModel->whereTime("create_time", 'last week')->where($where)->group('user_id')->select();
            $ret['users'] = count($us);
        } else if ($date == '本月') {

            $chargeAmount = $chargeModel->whereTime('create_time', 'month')->where($where)->sum('amount');
            $totalAmount = $shopOrderModel->whereTime("create_time", 'month')->where($where)->sum('amount');
            $totalOrder = $shopOrderModel->whereTime("create_time", 'month')->where($where)->count('id');
            $profit = $shopOrderProfitModel->whereTime('create_time', 'month')->where('shop_id', $shop_id)->sum('amount');

            $totalBalance = $shopOrderModel->whereTime('create_time', 'month')->where($where)->sum('balance');

            $ret['totalAmount'] = $totalAmount;
            $ret['totalOrder'] = $totalOrder;
            $ret['profit'] = $profit;
            $ret['chargeAmount'] = $chargeAmount;
            $ret['totalBalance'] = $totalBalance;


            $refundAmount = $shopOrderModel->whereTime('create_time', 'month')->where('status', 'refund')->where('shop_id', $shop_id)->sum('amount');
            $ret['refundAmount'] = $refundAmount;

            $us = $shopOrderModel->whereTime("create_time", 'month')->where($where)->group('user_id')->select();
            $ret['users'] = count($us);

        } else if ($date == '上月') {

            $chargeAmount = $chargeModel->whereTime('create_time', 'last month')->where($where)->sum('amount');
            $totalAmount = $shopOrderModel->whereTime("create_time", 'last month')->where($where)->sum('amount');
            $totalOrder = $shopOrderModel->whereTime("create_time", 'last month')->where($where)->count('id');
            $profit = $shopOrderProfitModel->whereTime('create_time', 'last month')->where('shop_id', $shop_id)->sum('amount');

            $totalBalance = $shopOrderModel->whereTime('create_time', 'last month')->where($where)->sum('balance');
            $ret['totalAmount'] = $totalAmount;
            $ret['totalOrder'] = $totalOrder;
            $ret['profit'] = $profit;
            $ret['chargeAmount'] = $chargeAmount;
            $ret['totalBalance'] = $totalBalance;

            $refundAmount = $shopOrderModel->whereTime('create_time', 'last month')->where('status', 'refund')->where('shop_id', $shop_id)->sum('amount');
            $ret['refundAmount'] = $refundAmount;


            $us = $shopOrderModel->whereTime("create_time", 'last month')->where($where)->group('user_id')->select();
            $ret['users'] = count($us);

        } else {


            $start = strtotime($startDate . " 00:00:00");
            $end = strtotime($endDate . " 23:59:59");
            $where['create_time'] = array("between", array($start, $end));


            $chargeAmount = $chargeModel->where($where)->sum('amount');
            $totalAmount = $shopOrderModel->where($where)->sum('amount');
            $totalOrder = $shopOrderModel->where($where)->count('id');
            $profit = $shopOrderProfitModel->where('shop_id', $shop_id)->sum('amount');

            $totalBalance = $shopOrderModel->where($where)->sum('balance');
            $ret['totalAmount'] = $totalAmount;
            $ret['totalOrder'] = $totalOrder;
            $ret['profit'] = $profit;
            $ret['chargeAmount'] = $chargeAmount;
            $ret['totalBalance'] = $totalBalance;

            $refundAmount = $shopOrderModel->where($where)->where('status', 'refund')->sum('amount');
            $ret['refundAmount'] = $refundAmount;


            $us = $shopOrderModel->where($where)->group('user_id')->select();
            $ret['users'] = count($us);

        }
        $this->success('', $ret);


    }

    /**
     * 订单趋势图
     */
    public function orders()

    {

        $shop_id = $this->request->param('shop_id');
        $startDate = $this->request->param('startDate');
        $endDate = $this->request->param('endDate');
        $date = time();
        $dateList = array();
        $dateList[] = date("Y-m-d", $date);
        for ($i = 1; $i <= 7; $i++) {
            $time = strtotime("-" . $i . " day");
            $dateList[] = date("Y-m-d", $time);
        }

        $newDateList = array();
        for ($i = count($dateList) - 1; $i >= 0; $i--) {
            $newDateList[] = $dateList[$i];
        }
        $shopOrderModel = new Shoporder();

        $ret = array();
        $d = array();
        $v = array();
        foreach ($newDateList as $key => $val) {

            $start = $val . " 00:00:00";
            $end = $val . " 23:59:59";
            $d[] = date("d", strtotime($start));

            $start = strtotime($start);
            $end = strtotime($end);
            $where = array();
            $where['create_time'] = array("between", array($start, $end));
            $where['shop_id'] = $shop_id;
            $where['status'] = array('not in', ['paying', 'refund']);

            $totalAmount = $shopOrderModel->where($where)->sum('amount');


            $v[] = $totalAmount;
        }

        $ret['key'] = $d;
        $ret['value'] = $v;


        $this->success('', $ret);
    }

    public function roomData()
    {

        $shop_id = $this->request->param('shop_id');
        $date = $this->request->param('date');
        $startDate = $this->request->param('startDate');
        $endDate = $this->request->param('endDate');
        $shopRoomModel = new Shoproom();
        $list = $shopRoomModel->where('shop_id', $shop_id)->select();

        $shopOrderModel = new Shoporder();


        foreach ($list as $key => $val) {
            $where = array();
            $where['room_id'] = $val['id'];
            $where['status'] = array('not in', ['paying', 'refund']);
            if ($date == '今天') {
                $amount = $shopOrderModel->whereTime('create_time', 'today')->where($where)->sum('amount');
            } else if ($date == '昨天') {
                $amount = $shopOrderModel->whereTime('create_time', 'yesterday')->where($where)->sum('amount');

            } else if ($date == '本周') {
                $amount = $shopOrderModel->whereTime('create_time', 'week')->where($where)->sum('amount');

            } else if ($date == '上周') {
                $amount = $shopOrderModel->whereTime('create_time', 'last week')->where($where)->sum('amount');

            } else if ($date == '本月') {
                $amount = $shopOrderModel->whereTime('create_time', 'month')->where($where)->sum('amount');

            } else if ($date == '上月') {
                $amount = $shopOrderModel->whereTime('create_time', 'last month')->where($where)->sum('amount');

            } else {

                $start = strtotime($startDate . " 00:00:00");
                $end = strtotime($endDate . " 23:59:59");
                $where['create_time'] = array("between", array($start, $end));

                $amount = $shopOrderModel->where($where)->sum('amount');
            }
            $list[$key]['amount'] = $amount;
        }

        usort($list, function ($a, $b) {
            return $b['amount'] - $a['amount'];
        });

        $this->success('', $list);
    }


    public function v2Index()
    {

        $shop_id = $this->request->param('shop_id');
        $startDate = $this->request->param('startDate');
        $endDate = $this->request->param('endDate');
        $where = array();
        $where['shop_id'] = $shop_id;

        $shopModel = new \app\admin\model\Shop();
        $shop = $shopModel->where('id', $shop_id)->find();


        $start = strtotime($startDate . " 00:00:00");
        $end = strtotime($endDate . " 23:59:59");
        $where['create_time'] = array("between", array($start, $end));

        //总收益
        $shopOrderProfitModel = new Shoporderprofit();
        $profit = $shopOrderProfitModel->where($where)->sum('amount');

        //商家全国平台充值收益
        $shopBalanceProfitModel = new Shopbalanceprofit();
        $balanceProfit = $shopBalanceProfitModel->where($where)->sum('amount');

        //充值-流水
        $chargeModel = new Shopcharge();
        $chargeAmount = $chargeModel->where('status', 'payed')->where($where)->sum('amount');

        //团购券-流水
        $tuanOrderModel = new Tuanorder();
        $tuan = $tuanOrderModel->where($where)->where('status', 'payed')->sum('amount');

        //--棋牌--
        $shopOrderModel = new Shoporder();
        //棋牌流水
        $qp = $shopOrderModel->where($where)->where('status', 'in', ['payed', 'done', 'doing'])->sum('amount');
        //棋牌订单
        $qp_num = $shopOrderModel->where($where)->where('status', 'in', ['payed', 'done', 'doing'])->count('id');
        //棋牌实付
        $qp_pay = $shopOrderModel->where($where)->where('status', 'in', ['payed', 'done', 'doing'])->where('pay_amount', ">", 0)->sum('pay_amount');
        //棋牌-美团-流水
        $qp_mt = $shopOrderModel->where($where)->where('status', 'in', ['payed', 'done', 'doing'])->where('mt_code', "<>", '')->sum('amount');
        //棋牌-抖音-流水
        $qp_dou = $shopOrderModel->where($where)->where('status', 'in', ['payed', 'done', 'doing'])->where('dou_code', "<>", '')->sum('amount');
        //棋牌-余额-流水
        $qp_balance = $shopOrderModel->where($where)->where('status', 'in', ['payed', 'done', 'doing'])->where('balance', ">", 0)->sum('balance');
        //棋牌-团购券-流水
        $qp_tuan = $shopOrderModel->where($where)->where('status', 'in', ['payed', 'done', 'doing'])->where('tuan_id', ">", 0)->sum('amount');
        //棋牌-退款-流水
        $qp_refund = $shopOrderModel->where($where)->where('status', 'refund')->sum('amount');

        $qpData = array();
        $qpData['amount'] = $qp;
        $qpData['num'] = $qp_num;
        $qpData['pay_amount'] = $qp_pay;
        $qpData['mt'] = $qp_mt;
        $qpData['dou'] = $qp_dou;
        $qpData['balance'] = $qp_balance;
        $qpData['tuan'] = $qp_tuan;
        $qpData['refund'] = $qp_refund;

        //台球-余额-流水
        //$userBalanceModel = new Userbalance();
        //$tq_balance = $userBalanceModel->where($where)->where('from', 'tq')->sum('amount');

        $tqData = array();
        $tqData['amount'] = 0.00;
        $tqData['num'] = 0.00;
        $tqData['pay_amount'] = 0.00;
        $tqData['mt'] = 0.00;
        $tqData['dou'] = 0.00;
        $tqData['balance'] = 0.00;
        $tqData['refund'] = 0.00;
        if ($shop['is_table'] == 1) {

            $shopTableOrderModel = new Shoptableorder();
            
            //台球统计以订单结束【book_end】时间为准
            $whereTq = array();
            $whereTq['shop_id'] = $shop_id;
            $whereTq['book_end'] = array("between", array($start, $end));

            //台球流水
            $tq = $shopTableOrderModel->where($whereTq)->where('status', 'in', ['payed', 'doing', 'done'])->sum('amount');
            //台球订单数量
            $tq_num = $shopTableOrderModel->where($whereTq)->where('status', 'in', ['payed', 'done', 'doing'])->count('id');
            //台球实付
            $tq_pay = $shopTableOrderModel->where($whereTq)->where('status', 'in', ['doing', 'done'])->where('pay_amount', ">", 0)->sum('pay_amount');
            //台球-美团-流水
            $tq_mt = $shopTableOrderModel->where($whereTq)->where('status', 'in', ['payed', 'done', 'doing'])->where('mt_code', "<>", '')->sum('amount');
            //台球-抖音流水
            $tq_dou = $shopTableOrderModel->where($whereTq)->where('status', 'in', ['payed', 'done', 'doing'])->where('dou_code', "<>", '')->sum('amount');
            //台球-余额-流水
            $tq_balance = $shopTableOrderModel->where($whereTq)->where('status', 'in', ['payed', 'done', 'doing'])->where('balance', ">", 0)->sum('balance');
            //台球-退款-流水
            $tq_refund = $shopTableOrderModel->where($whereTq)->where('status', 'refund')->sum('amount');

            $tqData['amount'] = $tq;
            $tqData['num'] = $tq_num;
            $tqData['pay_amount'] = $tq_pay;
            $tqData['mt'] = $tq_mt;
            $tqData['dou'] = $tq_dou;
            $tqData['balance'] = $tq_balance;
            $tqData['refund'] = $tq_refund;

        }

        //总流水  =  棋牌+ 团购券+充值+台球
        $total = $qpData['amount'] + $chargeAmount + $tuan + $tqData['amount'];

        $mt = $qpData['mt'] + $tqData['mt'];
        $dou = $qpData['dou'] + $tqData['dou'];
        $balance = $qpData['balance'] + $tqData['balance'];
        $refund = $qpData['refund'] + $tqData['refund'];

        $ret = array();
        $ret['shop_type'] = $shop['shop_type'];
        $ret['amount'] = formatMoney($total);
        $ret['profit'] = formatMoney($profit + $balanceProfit);
        $ret['charge'] = formatMoney($chargeAmount);

        $ret['qp'] = formatMoney($qp);
        $ret['tuan'] = formatMoney($tuan);
        $ret['tq'] = formatMoney($tqData['amount'] );
        $ret['mt'] = formatMoney($mt);
        $ret['dou'] = formatMoney($dou);
        $ret['balance'] = formatMoney($balance);
        $ret['refund'] = formatMoney($refund);
        $ret['qpData'] = $qpData;
        $ret['tqData'] = $tqData;

        $this->success('', $ret);

    }

    public function v2Order()
    {

        $shop_id = $this->request->param('shop_id');
        $startDate = $this->request->param('startDate');
        $endDate = $this->request->param('endDate');

        $timestamp1 = strtotime($startDate);
        $timestamp2 = strtotime($endDate);

        $diff_seconds = $timestamp2 - $timestamp1;
        $diff_days = floor($diff_seconds / (60 * 60 * 24));

        $where = array();
        $where['shop_id'] = $shop_id;
        $dayTrayModel = new Shopdaytrade();
        if ($diff_days == 0) {
            //24小时
            $date1 = "00:00~04:00";
            $date2 = "04:00~08:00";
            $date3 = "08:00~12:00";
            $date4 = "12:00~16:00";
            $date5 = "16:00~20:00";
            $date6 = "20:00~23:59";

            $dates = array();
            $dates[] = $date1;
            $dates[] = $date2;
            $dates[] = $date3;
            $dates[] = $date4;
            $dates[] = $date5;
            $dates[] = $date6;


            $result = array();
            $result['key'] = [4, 8, 12, 16, 20, 23];
            $values = array();
            $shopOrderModel = new Shoporder();
            foreach ($dates as $key => $val) {
                $time = explode("~", $val);
                $start = strtotime($startDate . " " . $time[0]);
                $end = strtotime($startDate . " " . $time[1]);

                $where = array();
                $where['create_time'] = array("between", array($start, $end));
                $where['shop_id'] = $shop_id;
                $where['status'] = array('not in', ['paying', 'refund']);

                $totalAmount = $shopOrderModel->where($where)->sum('amount');
                $values[] = $totalAmount;
            }

            $result['value'] = $values;

            $this->success('', $result);
        } else if ($diff_days <= 7) {

            $dates = array();
            for ($i = 0; $i <= $diff_days; $i++) {

                $date = strtotime("+" . $i . " day", $timestamp1);
                $dates[] = date("Y-m-d", $date);

            }

            $result = array();
            $keys = array();
            $values = array();
            foreach ($dates as $key => $val) {
                $start = strtotime($val . " 00:00:00");
                $end = strtotime($val . " 23:59:59");

                $where['create_time'] = array("between", array($start, $end));
                $trady = $dayTrayModel->where($where)->find();
                if ($trady) {
                    $keys[] = date("m-d", $start);
                    $values[] = $trady['book_amount'];
                } else {
                    $keys[] = date("m-d", $start);;
                    $values[] = 0;
                }
            }
            $result['key'] = $keys;
            $result['value'] = $values;

            $this->success('', $result);

        } else {
            $dates = array();

            $num = floor($diff_days / 7);
            for ($i = 0; $i <= 7; $i++) {

                $date = strtotime("+" . floor($i * $num) . " day", $timestamp1);
                $dates[] = date("Y-m-d", $date);

            }

            $result = array();
            $keys = array();
            $values = array();
            foreach ($dates as $key => $val) {
                $start = strtotime($val . " 00:00:00");
                $end = strtotime($val . " 23:59:59");

                if ($key != 6) {
                    $where['create_time'] = array("between", array($start, $end));
                    $trady = $dayTrayModel->where($where)->find();
                    if ($trady) {
                        $keys[] = date("m-d", $start);
                        $values[] = $trady['book_amount'];
                    } else {
                        $keys[] = date("m-d", $start);;
                        $values[] = 0;
                    }
                }

            }
            $result['key'] = $keys;
            $result['value'] = $values;

            $this->success('', $result);
        }


    }

    public function v2Room()
    {

        $shop_id = $this->request->param('shop_id');
        $startDate = $this->request->param('startDate');
        $endDate = $this->request->param('endDate');
        $shopRoomModel = new Shoproom();
        $list = $shopRoomModel->where('shop_id', $shop_id)->select();
        $shopOrderModel = new Shoporder();
        foreach ($list as $key => $val) {
            $where = array();
            $where['room_id'] = $val['id'];
            $where['status'] = array('not in', ['paying', 'refund']);
            $start = strtotime($startDate . " 00:00:00");
            $end = strtotime($endDate . " 23:59:59");
            $where['create_time'] = array("between", array($start, $end));
            $amount = $shopOrderModel->where($where)->sum('amount');
            $count = $shopOrderModel->where($where)->count('id');

            $list[$key]['amount'] = $amount;
            $list[$key]['count'] = $count;


        }
        usort($list, function ($a, $b) {
            return $b['amount'] - $a['amount'];
        });

        $this->success('', $list);
    }


    public function v2Member()
    {
        $shop_id = $this->request->param('shop_id');
        $startDate = $this->request->param('startDate');
        $endDate = $this->request->param('endDate');

        $shopOrderModel = new Shoporder();
        $where = array();
        $where['shop_id'] = $shop_id;
        $where['status'] = array('not in', ['paying', 'refund']);
        $start = strtotime($startDate . " 00:00:00");
        $end = strtotime($endDate . " 23:59:59");
        $where['create_time'] = array("between", array($start, $end));
        $list = $shopOrderModel->where($where)->group('user_id')->select();

        $userModel = new \app\admin\model\User();
        foreach ($list as $key => $val) {
            $user = $userModel->where('id', $val['user_id'])->find();
            $list[$key]['mobile'] = $user['mobile'];
            $list[$key]['username'] = $user['username'];
            $where['user_id'] = $val['user_id'];
            $amount = $shopOrderModel->where($where)->sum('amount');
            $count = $shopOrderModel->where($where)->count('id');

            $list[$key]['amount'] = $amount;
            $list[$key]['count'] = $count;

        }
        usort($list, function ($a, $b) {
            return $b['amount'] - $a['amount'];
        });

        $this->success('', $list);
    }

    public function shopDay()
    {
        $shop_id = $this->request->param('shop_id');
        $startTime = $this->request->param('startTime');
        $endTime = $this->request->param('endTime');
        $where = array();
        $where['shop_id'] = $shop_id;
        $start = strtotime($startTime . " 00:00:00");
        $end = strtotime($endTime . " 23:59:59");
        $where['create_time'] = array("between", array($start, $end));

        $shopTradeModel = new Shopdaytrade();
        $list = $shopTradeModel->where($where)->order('create_time', 'desc')->select();
        foreach ($list as $key => $val) {
            $list[$key]['create_time_txt'] = date("Y-m-d", $val['create_time']);
        }
        $amount = $shopTradeModel->where($where)->order('create_time', 'desc')->sum('book_amount');

        $ret = array();
        $ret['list'] = $list;
        $ret['amount'] = $amount;

        $this->success('', $ret);

    }

}
